package site.marqstree.kotlin.library.good.ui.fragment.cartlist

import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mcxtzhang.lib.AnimShopButton
import com.mcxtzhang.lib.IOnAddDelListener
import site.marqstree.kotlin.library.base.ui.widget.recyclerview.DataBindingAdapter
import site.marqstree.kotlin.library.base.util.rxbus.RxBus
import site.marqstree.kotlin.library.good.R
import site.marqstree.kotlin.library.good.databinding.ItemCartBinding
import site.marqstree.kotlin.library.good.ui.bean.GoodVOBean
import site.marqstree.kotlin.library.good.ui.fragment.cartlist.event.EventItemCountChange


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.good.ui.fragment.cartlist
 * 文件名: CartListAdapter
 * 创建者: marqstree
 * 创建时间: 2020/3/20 14:02
 * 描述: TODO
 */
class CartListAdapter: DataBindingAdapter<ItemCartBinding, GoodVOBean>(
    R.layout.item_cart,
    site.marqstree.kotlin.library.good.BR.goodVOBean,
    site.marqstree.kotlin.library.good.BR.presenter,
    CartItemPresenter())
{
    override fun convert(helper: BaseViewHolder, item: GoodVOBean) {
        super.convert(helper, item)
        val mCartGoodCountBtn = helper.getView<AnimShopButton>(R.id.mCartGoodCountBtn)
        val binding: ItemCartBinding = helper.getBinding()!!
        mCartGoodCountBtn.setOnAddDelListener(object : IOnAddDelListener {
            override fun onDelSuccess(p0: Int) {
                binding.goodVOBean?.count?.set(mCartGoodCountBtn.count)
                RxBus.send(EventItemCountChange())
            }
            override fun onAddSuccess(p0: Int) {
                binding.goodVOBean?.count?.set(mCartGoodCountBtn.count)
                RxBus.send(EventItemCountChange())
            }
            override fun onAddFailed(p0: Int, p1: IOnAddDelListener.FailType?) {
            }
            override fun onDelFaild(p0: Int, p1: IOnAddDelListener.FailType?) {
            }
        })
    }
}